const fs = require('fs');
const http = require('https');
const https = require('https');
const path = require('path');
// 下载文件
const downlaodFile = async (url, filepath) => {
    filepath = path.resolve(__dirname, filepath);
    const request = url.startsWith('https') ? https : http;
    return new Promise((resolve, reject) => {
        const fileStream = fs.createWriteStream(filepath);
        request.get(url, (response) => {
            if (response.statusCode === 200) {
                response.pipe(fileStream);
                fileStream.on('finish', resolve);
            } else {
                // 如果状态码不是200，认为是失败
                reject(new Error(`下载失败，状态码: ${response.statusCode}`));
            }
        })
    });
}
module.exports = [
    downlaodFile
]